<?php
namespace View;
class NavigationView 
{
	private static $postId = "postId";
	
	// returnerar true om urlen har postid
	public static function isViewingPost()
	{
		if (isset($_GET[self::$postId]))
		{
			return true;
		}
		else 
		{
			return false;		
		}	
	}
	public static function getPostList()
	{
		return"?";
	}
	// två olika redirect functioner 
	public static function Redirect($time,$url)
	{
		return header('Refresh:'. $time .';'.'Url='.$url);
	}
	public static function Location($url)
	{
		return header('Location:'.$url);
	}
	// hämtar ut postens id 
	public static function getPostLink(\Model\Blogg $blogg)
	{
		return"?". self::$postId. "=" . $blogg->getPostId();
	}
	// returnerar vilken post som ska visas med idet 
	public static function getSelectedPost(\Model\Blogglist $blogglist, \Common\Database $db)
	{
		if (isset($_GET[self::$postId]))
		{
			$urlId = $_GET[self::$postId];
			if ($urlId != "0" && intval($urlId)== 0)
				{
					throw new Exception("getSelectedPost() url format failure");
				}
				else 
				{
					$postId = intval($urlId);
					return $blogglist->getPostByID($postId, $db);	
				}
		}
		else
		{
			throw new Exception("GetSelectedPost() can only be called when viewing post");
		}
	}
}
